---
title: withinRange
description: The withinRange function can be used to ensure that a number is within the optional min and max values.
docType: API Docs
docGroup: Numbers
group: Utils
---

# withinRange [$SOURCE](packages/core/src/utils/withinRange.ts)

```ts disableTransform
function withinRange(options: WithinRangeOptions): number;
```

The `withinRange` function can be used to ensure that a number is within
the optional `min` and `max` values.

## Example Usage

```ts disableTransform
import { withinRange } from "@react-md/core/utils/withinRange";

expect(withinRange({ value: 100, min: undefined, max: undefined })).toBe(100);
expect(withinRange({ value: 0, min: undefined, max: undefined })).toBe(0);
expect(withinRange({ value: -100, min: undefined, max: undefined })).toBe(-100);
expect(withinRange({ value: 0, min: 0, max: 10 })).toBe(0);
expect(withinRange({ value: -1, min: 0, max: 10 })).toBe(0);
expect(withinRange({ value: -0.00000001, min: 0, max: 10 })).toBe(0);
expect(withinRange({ value: 20, min: 0, max: 20 })).toBe(20);
expect(withinRange({ value: 20, min: 0, max: 19 })).toBe(19);
expect(withinRange({ value: 10.5, min: 10, max: 11 })).toBe(10.5);
expect(withinRange({ value: 10.5, min: 9, max: 10 })).toBe(10);
```

## Parameters

- `options` - an object with the following definition:

```ts disableTransform
export interface WithinRangeOptions {
  min: number | undefined;
  max: number | undefined;
  value: number;
}
```

## Returns

The number.
